<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
/**
 * 好友模块控制器
 */
class Mfriend extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('finance_list_model');
        $this->load->model('experience_list_model');
        $this->load->model('users_spread_model');
        $this->assign("module", "mfriend");
        $this->month_en_to_ch = array(1=>"一",2=>"二",3=>"三",4=>"四",5=>"五",6=>"六",7=>"七",8=>"八",9=>"九",10=>"十",11=>"十一",12=>"十二");
    }
    //新手任务首页
    function index() {
        $this->sso_login();
        
        $where = array();
        $where['parent_id'] = $this->userinfo['user_id'];
        //总推广人数
        $total_count = $this->users_spread_model->get_user_total_count($where);
        $where = array();
        $where['reward_type'] = 'spread_award';//邀请类型奖励
        $where['user_id'] = $this->userinfo['user_id'];
        //总要求收益
        $total_finance =$this->finance_list_model->get_finance_total_count($where);
        //总要求积分
        $total_experience = $this->experience_list_model->get_experience_total_count($where);
        $total_count = str_split(str_pad($total_count, 3, 0,STR_PAD_LEFT));
        
        if($this->user_info){
            $spread_url = www_base_url(encrypt_user_id($this->user_info['user_id']));
        }else{
            $spread_url = www_base_url();
        }
        
        //邀请排行
        $this_month = date("Ym");
        $where = array();
        $where['month'] = $this_month;
        $where['reward_type'] = "spread_award";
        $list = $this->finance_list_model->getSpreadAmount($where,0,10);
        foreach ($list as $key => $val) {
            $list[$key]['username'] = name_formart($val['username']);
            $list[$key]['nickname'] = $val['nickname'] ? nick_formart($val['nickname']) : '';
            $list[$key]['total_award'] = number_format($val['total_award']);
            $list[$key]['head_img'] = strstr($val['head_img'], "http://") ? $val['head_img'] : $this->img_url.$val['head_img'];
        }
        $this->assign('list', $list);
        $this->assign('month', $this->month_en_to_ch[intval(date("m"))]);
        
        $this->assign("num1", $total_count[2] ? $total_count[2] : 0);
        $this->assign("num2", $total_count[1] ? $total_count[1] : 0);
        $this->assign("num3", $total_count[0] ? $total_count[0] : 0);
        $this->assign("total_finance", number_format($total_finance));
        $this->assign("total_experience", number_format($total_experience));
        $this->assign("spread_url", $spread_url);
        $this->display('mfriend/index.html');
    }
}
